home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 361_01 / cursor.c < prev    next >
C/C++ Source or Header  |  1991-09-18  |  2KB  |  102 lines

  1.  
  2. /* Cursor.c --> A Collection of Text Cursor Manipulation Tools
  3.  *
  4.  * Author: J.Ekwall                                     13 September 91
  5.  *
  6.  * Copyrighted to the Public Domain.  Unlimited Distribution Authorized.
  7.  *
  8.  * User Assumes All Risks/Liabilities.
  9.  *
  10.  * Last Update: 13 September 91/EK
  11.  */
  12.  
  13. #include <stdek.h>
  14. #include <gadgets.h>
  15. #include <dos.h>
  16.  
  17. void CursorBwd(int N)
  18. /* Move the cursor N cols to the left */
  19. {
  20.     int xx, yy;
  21.  
  22.     Getxy(&xx, &yy);
  23.     if ((xx -= (N % 80)) < 1) { xx -= 80; if (--yy < 1) yy = 25; }
  24.     Gotoxy(xx, yy);
  25. }
  26.  
  27. void CursorDn(int N)
  28. /* Move the down N rows & wrap to top if the cursor is on the last row */
  29. {
  30.     int xx, yy;
  31.     
  32.     Getxy(&xx, &yy); if ((yy += (N % 25)) > 25) yy -= 25; Gotoxy(xx, yy);
  33. }
  34.  
  35. void CursorFwd(int N)
  36. /* Move the cursor N cols to the right */
  37. {
  38.     int xx, yy;
  39.  
  40.     Getxy(&xx, &yy);
  41.     if ((xx += (N % 80)) > 80) { xx = 1; if (++yy > 25) yy = 1; }
  42.     Gotoxy(xx, yy);
  43. }
  44.  
  45. void CursorNL(int N) 
  46. /* Move the cursor to the beginning of the next row  */
  47. {
  48.     int xx, yy;
  49.     
  50.     Getxy(&xx, &yy); if ((yy += (N % 25)) > 25) yy = 1; Gotoxy(0, yy);
  51. }
  52.  
  53. void CursorUP(int N)
  54. /* Move the cursor N rows up */
  55. {
  56.     int xx, yy;
  57.  
  58.     Getxy(&xx, &yy); if ((yy -= (N % 25)) < 1) yy = 25; Gotoxy(xx, yy);
  59. }
  60.  
  61. int Getxy(int *X, int *Y)
  62. {
  63.     union REGS rg;
  64.  
  65.     rg.h.bh = 0; rg.h.ah = 3; int86(0x10, &rg, &rg);
  66.     *X = rg.h.dl + 1; *Y = rg.h.dh + 1;
  67.     return !(rg.h.ch & 0x20);           /* True if Cd_Cursor */
  68. }
  69.  
  70. void Gotoxy(X, Y)
  71. /* RePosition cursor to (X, Y) */
  72. {
  73.     union REGS rg;
  74.  
  75.     rg.h.ah = 2; rg.h.dh = --Y; rg.h.dl = --X; rg.h.bh = 0;
  76.     int86(0x10, &rg, &rg);
  77. }
  78.  
  79. int HideCursor(void)
  80. /* Turn the cursor off */
  81. {
  82.     int Visible;
  83.     union REGS rg;
  84.  
  85.     rg.h.bh = 0;     rg.h.ah = 3; int86(0x10, &rg, &rg);
  86.     if ((Visible = !(rg.h.ch & 0x20)) != 0) {
  87.        rg.h.ch |= 0x20; rg.h.ah = 1; int86(0x10, &rg, &rg); }
  88.     return Visible;
  89. }
  90.  
  91. void ShowCursor(int Fat)
  92. {
  93.     static int Virgin = 0;
  94.     union REGS rg;
  95.  
  96.     rg.h.bh = 0; rg.h.ah = 3; int86(0x10, &rg, &rg);    
  97.     if (!Virgin) Virgin = rg.h.ch;
  98.     rg.h.ah = 1; rg.h.ch = 0; if (!Fat) rg.h.ch = Virgin;
  99.     rg.h.ch &= 0x1F; int86(0x10,&rg,&rg);
  100. }
  101.  
  102.